#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#define BUFFER_SIZE 512

int main(int argc, char **argv)
{
    if (argc != 3)
    {
        printf("Usage: %s source dest\n", argv[0]);
        return 1;
    }

    // 自动创建源文件
    int src_fd = open(argv[1], O_RDONLY | O_CREAT, 0644);
    if (src_fd == -1)
    {
        perror("open source");
        return 1;
    }

    int dest_fd = creat(argv[2], 0644);
    char buf[BUFFER_SIZE];
    ssize_t num;

    while ((num = read(src_fd, buf, BUFFER_SIZE)) > 0)
    {
        write(dest_fd, buf, num);
    }

    close(src_fd);
    close(dest_fd);
    return 0;
}